package com.tf_cut.backend.datadic.controller;

import com.alibaba.fastjson.JSON;
import com.tf_cut.backend.datadic.service.IDatadicService;
import com.tf_cut.backend.datadic.vo.DatadicVo;
import com.tf_cut.backend.person.vo.PersonAndAccountVo;
import com.tf_cut.backend.util.SendMail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/backend")
public class DatadicController {

    @Autowired
    private IDatadicService datadicService;

    @Autowired
    private SendMail sendMail;

    @GetMapping("/dict/getShowTime")
    public String getShowTime(){
        List<DatadicVo> list = datadicService.qryDatadicByCode("SHOW_BUTTON");
        return JSON.toJSONString(list);
    }

    @GetMapping("/dict/getdataDicVo")
    public List<DatadicVo> getdataDicVoWithCode(@RequestParam("dataicCode") String dataicCode){
        List<DatadicVo> list = datadicService.qryDatadicByCode(dataicCode);
        return list;
    }

    @RequestMapping("/dict/updDatadic")
    public int updDatadic(String json){
        DatadicVo datadicVo = JSON.parseObject(json,DatadicVo.class);
        return datadicService.updateDatadic(datadicVo);
    }
    
    @GetMapping("/dict/chargeInfoMailSend")
    public void chargeInfoMailSend(@RequestParam("sellerName")String sellerName,@RequestParam("investAmount")String investAmount,@RequestParam("createTime")String createTime){
    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    	sendMail.chargeInfoMailSend(sellerName,investAmount,formatter.format(createTime));
    }

    @GetMapping("/dict/sendMail")
    public String sendMail(@RequestParam("flag") String flag,@RequestParam("name") String name,@RequestParam("money") String money,@RequestParam("time") String time){
        switch (flag){
            case "1":
            	PersonAndAccountVo avo = new PersonAndAccountVo();
            	avo.setPersonName(name);
            	avo.setMobile(money);
            	avo.setCardCode(time);
                sendMail.registerInfoMailSend(avo);
                break;
            case "2":
                sendMail.chargeInfoMailSend(name,money,time);
                break;
            case "3":
                sendMail.distributeInfoMailSend(name,money,time);
                break;
            case "4":
                sendMail.withdrawMailSend();
                break;
            case "5":
                sendMail.billInfoMailSend(name,money,time);
                break;
            case "6":
                sendMail.invoiceAlertMailSend(name,money,time);
                break;
            default:
                break;
        }
        return "success";
    }
}
